import Vue from 'vue'
import App from './App.vue'
import routes from './router'
import VueRouter from 'vue-router'
import store from './store'
Vue.config.productionTip = false
let router = null;
let instance = null;
function render(props = {}) {
  const { container } = props;
  router = new VueRouter({
    // base: window.__POWERED_BY_QIANKUN__ ? '/react' : '/',
    // base: window.__POWERED_BY_QIANKUN__ ? props.base : '/',
    base: window.__POWERED_BY_QIANKUN__ ? '/react' : '/child/react/',
    mode: 'history',
    routes,
  });

  instance = new Vue({
    router,
    store,
    render: (h) => h(App),
  }).$mount(container ? container.querySelector('#react') : '#react');
  // 更改了静态页面的div的id为你的项目 id vue
}

// 独立运行时
if (!window.__POWERED_BY_QIANKUN__) {
  render();
}

export async function bootstrap() {
  console.log('子项目输出： react 项目开始加载..');
}
export async function mount(props) {
  console.log('子项目输出： react 项目加载完成 ：传入的默认属性为：', props);
  render(props);
}
export async function unmount() {
  console.log('子项目输出： react 卸载了');
  instance.$destroy();
  instance.$el.innerHTML = '';
  instance = null;
  router = null;
}
// 只适用于 手动加载 ，静态配置的不支持
export async function update(props) {
  console.log('子项目输出： react 更新了，传入的属性为', props);
}